package com.zhangyue.programmer.common;

public class R<T> {
    private int code;
    private String message;
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public static <T> R<T> ok(){
        R<T> r = new R<>();
        r.code = 0;
        r.message = "";
        return r;
    }
    public static <T> R<T> ok(T t){
        R<T> r = new R<>();
        r.code = 0;
        r.message = "";
        r.data = t;
        return r;
    }

    public static <T> R<T> failed(T t){
        return failed(t,"");
    }
    public static R error(String t){
        return failed(null,t);
    }

    public static <T> R<T> failed(T t,String message){
        R<T> r = new R<>();
        r.code = 500;
        r.message = message;
        r.data = t;
        return r;
    }
}
